Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support section variable in manual url #8494

Merged
merged 8 commits into from
Dec 14, 2024

Conversation

wangf1122
Copy link
Collaborator

The manual url can be more flexible. In some places, the url can be like https://something/subsection?lang=eng ect. So I am adding section variable as part of the url pattern and the front end Javascript will handle this pattern as well.

image

Checklist

  • I have read the contribution guidelines
  • Pull request provided for main branch, backports managed with label
  • Good housekeeping of code, cleaning up comments, tests, and documentation
  • Clean commit history broken into understandable chucks, avoiding big commits with hundreds of files, cautious of reformatting and whitespace changes
  • Clean commit messages, longer verbose messages are encouraged
  • API Changes are identified in commit messages
  • Testing provided for features or enhancements using automatic tests
  • User documentation provided for new features or enhancements in manual
  • Build documentation provided for development instructions in README.md files
  • Library management using pom.xml dependency management. Update build documentation with intended library use and library tutorials or documentation

@wangf1122 wangf1122 marked this pull request as ready for review November 8, 2024 14:39
@ianwallen ianwallen added this to the 4.4.7 milestone Nov 11, 2024
@ianwallen
Copy link
Contributor

I wonder if we want to make {{section}} optional and if it does not exists then append section at the end. (Which seem to be the current logic)

Of if we just want to treat is as required if want to use it.
i.e. should we support url like http://example.com?lang=en that would not include the section.
Otherwise, the current implementation will always append the section so http://example.com?lang=en would turn into http://example.com?lang=en/section which would cause issues. And to get around this we would need to add http://example.com?lang=en&dummy={{section}} to add a dummy section that is not used.

If we do want {{section}} to be mandatory to be used then I suspect that the section will need to be added to existing urls

UPDATE Settings SET value = CONCAT(value, '{{section}}') WHERE name = 'system/documentation/url';

Also you will need to update the following.

INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('system/documentation/url', 'https://docs.geonetwork-opensource.org/{{version}}/{{lang}}', 0, 570, 'n');
To

INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('system/documentation/url', 'https://docs.geonetwork-opensource.org/{{version}}/{{lang}}/{{section}}', 0, 570, 'n');

What do other think?

@ianwallen ianwallen requested a review from josegar74 November 11, 2024 13:49
@josegar74
Copy link
Member

@ianwallen I think it is fine if the placeholder is optional

Copy link
Member

@josegar74 josegar74 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change works, but with the current code this kind of URL doesn't work:

https://something/subsection?lang=eng

The lang placeholder replacement checks for /{{lang}} instead of {{lang}}. This is not changed in the PR, but not sure why the original code has the /.


The official manual adds the language as part of the URL path, not as a parameter:

https://docs.geonetwork-opensource.org/4.4/fr/overview/

I assume you have some customised documentation that uses language as a parameter?

@wangf1122 wangf1122 force-pushed the main.section.variable.manual.url branch from 2e70774 to 0b000ce Compare November 13, 2024 20:12
@wangf1122 wangf1122 requested a review from josegar74 November 13, 2024 20:53
@wangf1122
Copy link
Collaborator Author

The change works, but with the current code this kind of URL doesn't work:

https://something/subsection?lang=eng

The lang placeholder replacement checks for /{{lang}} instead of {{lang}}. This is not changed in the PR, but not sure why the original code has the /.

The official manual adds the language as part of the URL path, not as a parameter:

https://docs.geonetwork-opensource.org/4.4/fr/overview/

I assume you have some customised documentation that uses language as a parameter?

@josegar74

The original has / is because it doesn't like to parse English into the default document.

For example:

https://docs.geonetwork-opensource.org/4.2/user-guide/describing-information/creating-metadata/

vs French version

https://docs.geonetwork-opensource.org/4.2/fr/user-guide/describing-information/creating-metadata/.

Now if we ignore that "/" logic, we will end up with default English url as:
https://docs.geonetwork-opensource.org/4.2//user-guide/describing-information/creating-metadata/ which seems to be fine. I could make such logic by ignoring such slash

if (baseUrl.includes("{{section}}")) {
helpPageUrl = baseUrl.replace("{{section}}", page);
} else {
helpPageUrl = baseUrl + "/" + page;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add the "/"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the default original code.

The default manual.json of each section contains was appended at the end of the url and they contain no such "/". So the Javascript has to add them

"creating-metadata": "user-guide/describing-information/creating-metadata/",

@@ -152,20 +152,30 @@
if (gnGlobalSettings.lang !== "en") {
baseUrl = scope.helpBaseUrl.replace("{{lang}}", gnGlobalSettings.lang);
} else {
baseUrl = scope.helpBaseUrl.replace("/{{lang}}", "");
baseUrl = scope.helpBaseUrl.replace("{{lang}}", "");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be "."

i.e. there are 2 urls.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I think about it, it does not make sense to user "." either because someone could use ?lang={{lang}} and it would be odd to add "." and ?lang=. would not make sense!
So I guess "" is better in this case.
Maybe there could be another replace on the url after the replace to remove all the double "//"

As for why there is a odd case where lang = ""
What if it treated gnGlobalSettings.lang !== "en" as if gnGlobalSettings.lang = null?
Then {{lang?en}} could mean that if lang is null then default to en
So you could add another replacement for the following.
baseUrl = scope.helpBaseUrl.replace("{{lang?en}}", "");

So gn could use
https://docs.geonetwork-opensource.org/4.2/{{lang}}/api/search/
And other sites that always want to have a language value for language could use
https://example.com/{{lang?en}}/api/search/?lang={{lang?en}} and it would result to en value.
But this would still be odd logic.

@CLAassistant
Copy link

CLAassistant commented Dec 8, 2024

CLA assistant check
All committers have signed the CLA.

@josegar74
Copy link
Member

I would keep the replacement to empty string and replace // in the URL path.

Please check this change to apply it in your code:

          /**
           * Processes an URL removing // characters in the URL path.
           *
           * @param url
           * @returns {string}
           */
          var processUrl = function(url) {
            var urlToProcess = new URL(url);
            urlToProcess.pathname = urlToProcess.pathname.replace(/\/\//g, "/");
            return urlToProcess.toString();
          }

          scope.showHelp = function () {
          ...
           var helpPageUrl;
            if (baseUrl.includes("{{section}}")) {
              helpPageUrl = baseUrl.replace("{{section}}", page);
            } else {
              helpPageUrl = baseUrl + "/" + page;
            }

            helpPageUrl = processUrl(helpPageUrl);

            testAndOpen(helpPageUrl).then(
              function () {},
              function () {
                var baseUrl = scope.helpBaseUrl
                  .replace("{{lang}}", "")
                  .replace("{{version}}", scope.applicationVersion);
                var helpPageUrl;
                if (baseUrl.includes("{{section}}")) {
                  helpPageUrl = baseUrl.replace("{{section}}", page);
                } else {
                  helpPageUrl = baseUrl + "/" + page;
                }

                helpPageUrl = processUrl(helpPageUrl);

                testAndOpen(helpPageUrl);
              }
              ...

@wangf1122
Copy link
Collaborator Author

@josegar74

This approach works fine. I did apply this into the code, please check

@josegar74
Copy link
Member

josegar74 commented Dec 12, 2024

@wangf1122
Copy link
Collaborator Author

@josegar74

Do you mean here? Please check this commit aa1e4ce

@josegar74
Copy link
Member

@wangf1122 I'm not sure what happened, but previously I missed that line. Looks all good.

@ianwallen ianwallen merged commit 91b82fa into geonetwork:main Dec 14, 2024
6 of 7 checks passed
@geonetworkbuild
Copy link
Collaborator

The backport to 4.2.x failed:

The process '/usr/bin/git' failed with exit code 1
stderr
error: could not apply 9901adac8f... support section variable in manual url
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config advice.mergeConflict false"

stdout
Auto-merging web-ui/src/main/resources/catalog/locales/en-admin.json
CONFLICT (content): Merge conflict in web-ui/src/main/resources/catalog/locales/en-admin.json

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-4.2.x 4.2.x
# Navigate to the new working tree
cd .worktrees/backport-4.2.x
# Create a new branch
git switch --create backport-8494-to-4.2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick 9901adac8f7b701ce5a8567381de94190032d9cd,0b000ce24b95fa22429836ed06a6a4bd8a68f16f,2e55b577807206f3fa9c79346c31dea2c5dd61f7,455dba0fd01cb09ad7ee284ca55b5a50353f7bc6,d50d853e56b034d84cef52d4c11339ea3dfc72d0,907583992ef95cb798aa78d3343a83ebf6b16d0c,a3b22a60c1a9b735877fcbb9f01494ebae777cc4,aa1e4cecceca522d5bcaf7fd7e1059a69d58bb29
# Push it to GitHub
git push --set-upstream origin backport-8494-to-4.2.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-4.2.x

Then, create a pull request where the base branch is 4.2.x and the compare/head branch is backport-8494-to-4.2.x.

wangf1122 added a commit to wangf1122/core-geonetwork that referenced this pull request Dec 16, 2024
* support section variable in manual url

* isoLang variable, help wording

* Revert "isoLang variable, help wording"

This reverts commit 0b000ce

* ignore path "/" for default language replacement

* Update web-ui/src/main/resources/catalog/locales/en-admin.json

Co-authored-by: Jose García <[email protected]>

* remove double slash

* remove double slash in error handler

---------

Co-authored-by: Jose García <[email protected]>
wangf1122 added a commit to wangf1122/core-geonetwork that referenced this pull request Dec 16, 2024
* support section variable in manual url

* isoLang variable, help wording

* Revert "isoLang variable, help wording"

This reverts commit 0b000ce

* ignore path "/" for default language replacement

* Update web-ui/src/main/resources/catalog/locales/en-admin.json

Co-authored-by: Jose García <[email protected]>

* remove double slash

* remove double slash in error handler

---------

Co-authored-by: Jose García <[email protected]>
josegar74 added a commit that referenced this pull request Dec 16, 2024
* support section variable in manual url (#8494)

* support section variable in manual url

* isoLang variable, help wording

* Revert "isoLang variable, help wording"

This reverts commit 0b000ce

* ignore path "/" for default language replacement

* Update web-ui/src/main/resources/catalog/locales/en-admin.json

Co-authored-by: Jose García <[email protected]>

* remove double slash

* remove double slash in error handler

---------

Co-authored-by: Jose García <[email protected]>

* support section variable in manual url (#8494)

* support section variable in manual url

* isoLang variable, help wording

* Revert "isoLang variable, help wording"

This reverts commit 0b000ce

* ignore path "/" for default language replacement

* Update web-ui/src/main/resources/catalog/locales/en-admin.json

Co-authored-by: Jose García <[email protected]>

* remove double slash

* remove double slash in error handler

---------

Co-authored-by: Jose García <[email protected]>

* Update NeedHelpDirective.js

prettier plugin reformating

---------

Co-authored-by: Jose García <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants